﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;
using System.Web.SessionState;
using DTcms.Web.UI;
using DTcms.Common;

namespace DTcms.Web.m
{
    /// <summary>
    /// baojia_add 的摘要说明
    /// </summary>
    public class baojia_add : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            //检查用户是否登录
            string user_name = DTRequest.GetFormString("txtUserName");
            string user_pwd = DTRequest.GetFormString("txtPassword");
            if (string.IsNullOrEmpty(user_name) || string.IsNullOrEmpty(user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"您的登录信息有误，请退出系统后重新登录！\"}");
                return;
            }
            Model.users userModel = new BLL.users().GetModel(user_name, user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"您的登录信息有误，请退出系统后重新登录！\"}");
                return;
            }
            int article_id = DTRequest.GetFormInt("article_id");
            string _remark = DTRequest.GetFormString("txtRemark");
            if (article_id == 0)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"抱歉，未指定信息ID！\"}");
                return;
            }
            if (string.IsNullOrEmpty(_remark))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入内容！\"}");
                return;
            }

            BLL.xunjia_baojia bll = new BLL.xunjia_baojia();
            Model.xunjia_baojia model = new Model.xunjia_baojia();

            model.article_id = article_id;
            model.user_id = userModel.id;
            model.remark = _remark;
            model.add_time = DateTime.Now;
            model.status = 0;

            if (bll.Add(model) > 0)
            {
                context.Response.Write("{\"status\": 1, \"msg\": \"报价信息提交成功！\"}");
                return;
            }
            context.Response.Write("{\"status\": 0, \"msg\": \"对不起，保存过程中发生错误！\"}");
            return;
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}